#pragma once
#include <Windows.h>
#include <gdiplus.h>

enum Reverse{
	normal=0,
	horizontal=1,
	vertical=2,
	verhor=3
};
class T_BITMAP{
protected:
	wchar_t *m_FilePath;
	HBITMAP hBMPs[4];
	HBITMAP *m_Cells;
	Gdiplus::SizeF m_Size;
	Gdiplus::SizeF m_CellSize;
	int m_Cols;
	int m_Rows;
	bool b_calc;
	bool bValid;
protected:
	T_BITMAP();
	void calc();
	bool init(wchar_t fileName[]);
	bool init(HBITMAP bmp,const Gdiplus::RectF &rect);
public:
	~T_BITMAP();
	static T_BITMAP *create(wchar_t fileName[],int c=1,int r=1);
	static T_BITMAP *create(HBITMAP bmp,const Gdiplus::RectF &rect,int c=1,int r=1);

	Gdiplus::SizeF getSize(){return m_Size;}
	void setCR(int c,int r);
	int getCols(){return m_Cols;}
	int getRows(){return m_Rows;}
	POINT getPoint( const Gdiplus::PointF &p);
	int getIndex(const Gdiplus::PointF &p);
	Gdiplus::SizeF getCellSize(){if(!b_calc)calc();return m_CellSize;}
	Gdiplus::RectF getBounds(const POINT &point);
	Gdiplus::RectF getBounds(int index);
	HBITMAP getRegion(int index,Reverse r=normal);
	HBITMAP getBMP(Reverse r=normal);
	bool isValid(){return bValid;}
	const wchar_t * getFilePath(){return m_FilePath;}
};